#ifndef ARRAY_H
#define ARRAY_H

namespace StructLib
{
    template <typename T>
    class Array : public Object
    {
    protected:
        T *m_array;

    public:
        virtual bool Set(int i, const T &e)
        {
            bool ret = ((0 <= i) && (i < Length()));

            if (ret)
            {
                m_array[i] = e;
            }

            return ret;
        }

        virtual bool Get(int i, T &e) const
        {
            bool ret = ((0 <= i) && (i < Length()));

            if (ret)
            {
                e = m_array[i];
            }

            return ret;
        }

        virtual int Length() const = 0;

        T &operator[](int i)
        {
            if ((0 <= i) && (i < Length()))
            {
                return m_array[i];
            }
            else
            {
                THROW_EXCEPTION(IndexOutOfBoundsException, "Parameter i is invalid...");
            }
        }

        T operator[](int i) const
        {
            return (const_cast<Array<T> &>(*this))[i];
        }
    };
} // namespace StructLib

#endif // !ARRAY_H